package com.teamfractal.fracdustry.client.overlay;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.teamfractal.fracdustry.client.config.FDClientConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

//Seems not working...
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class FDTitleOverlay{
    @OnlyIn(Dist.CLIENT)
    @SubscribeEvent(priority = EventPriority.HIGH)
    public static void eventHandler(GuiScreenEvent.DrawScreenEvent.Post event) {
        if (event.getGui() instanceof TitleScreen) {
            int w = event.getGui().width;
            int h = event.getGui().height;
            RenderSystem.disableDepthTest();
            RenderSystem.depthMask(false);
            RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
                    GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
            RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
            if (FDClientConfig.TITLE_ICON_DISPLAY.get())
            {RenderSystem.setShaderTexture(0,new ResourceLocation("fracdustry:textures/logo.png"));
                GuiComponent.blit(event.getMatrixStack(), FDClientConfig.ICON_LOC_X.get(), FDClientConfig.ICON_LOC_Y.get(), 0, 0, 64, 64, 64, 64);}
            if (FDClientConfig.TITLE_TEXT_DISPLAY.get())
            {Minecraft.getInstance().font.draw(event.getMatrixStack(),new TranslatableComponent("overlay.title.fracdustry")
                    ,FDClientConfig.TEXT_LOC_X.get(),FDClientConfig.TEXT_LOC_Y.get(),-1);}
            RenderSystem.depthMask(true);
            RenderSystem.enableDepthTest();
            RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
        }
    }
}
